#
# This file is a part of the open-eBackup project.
# This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
# If a copy of the MPL was not distributed with this file, You can obtain one at
# http://mozilla.org/MPL/2.0/.
#
# Copyright (c) [2024] Huawei Technologies Co.,Ltd.
#
# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
# EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
# MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
#

from pydantic import BaseModel, Field
from redis.common.const import SubJobType, ExecutePolicy


class CommonBodyErrorResponse(BaseModel):
    code: int = Field(default=0, description="执行结果")
    body_err: int = Field(None, description="错误码", alias='bodyErr')
    message: str = Field(default='', description="错误信息")


class RedisAppBaseInfo(BaseModel):
    uuid: str = Field(None, description='uuid')
    name: str = Field(default='', description='name')
    type: str = Field(default='Database', description='resource type')
    sub_type: str = Field(default='Redis', description='resource sub type', alias='subType')
    extend_info: dict = Field(default='', description='extend info', alias='extendInfo')


class QueryClusterResponse(RedisAppBaseInfo):
    endpoint: str = Field(default='', description='endpoint')
    nodes: list = Field(default=[], description='node info')


class RedisClusterNodeInfo(BaseModel):
    id: str = Field(default='', description='id')
    endpoint: str = Field(default='', description='endpoint')
    name: str = Field(default='', description='name')
    role: int = Field(default=1, description='node role')
    type: str = Field(default='Database', description='resource type')
    sub_type: str = Field(default='Redis', description='resource sub type', alias='subType')
    extend_info: dict = Field(default='', description='extend info', alias='extendInfo')


class ListAppResourceInfo(RedisAppBaseInfo):
    parent_uuid: str = Field(default='', description='parent uuid', alias='parentUuid')
    parent_name: str = Field(default='', description='parent name', alias='parentName')


class ListAppV2Response(BaseModel):
    resource_list: list = Field(default=[], description='resource list', alias='resourceList')
    page_no: int = Field(default=0, description='页号', alias='pageNo')
    pages: int = Field(default=1, description='总页数')
    page_size: int = Field(default=200, description='页大小', alias='pageSize')
    total: int = Field(default=0, description='总大小')


class PermissionInfo(BaseModel):
    user: str = Field(default='root', description='user')
    group: str = Field(default='root', description='group')
    file_mode: str = Field(default='0700', description='mod', alias='fileMode')


class GenerateSubJobInfo(BaseModel):
    job_id: str = Field(description='main job id', alias='jobId')
    sub_job_id: str = Field(description='sub job id', alias='subJobId')
    job_type: int = Field(default=SubJobType.BUSINESS_SUB_JOB.value, description='sub job type', alias='subJobId')
    job_name: str = Field(description='sub job type', alias='subJobName')
    job_priority: int = Field(default=None, description='job priority', alias='jobPriority')
    policy: int = Field(default=ExecutePolicy.FIXED_NODE.value, description='sub job execute by priority')
    ignore_failed: bool = Field(default=False, description='whether main job ignore this job executing result',
                                alias='ignoreFailed')
    exec_node_id: str = Field(description='sub job executing node uuid', alias='execNodeId')
    job_info: str = Field(description='extend job information', alias='jobInfo')
